package gspushmq.v1.app.subscribeapp.enumeration;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum  LinkEnum {
    INNER(1,"内链"),
    OUTER(2,"外链"),
    NONE(0,"无链接");

    int code;
    String value;

    LinkEnum(int code, String value) {
        this.code = code;
        this.value = value;
    }
    public static boolean contain(Integer code){
        if (code == null)
            return false;
        for (LinkEnum en : LinkEnum.values())
            if (en.getCode() == code)
                return true;
        return false;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public static List<Map<String, Object>> toMap(){
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for(LinkEnum type : LinkEnum.values()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("code", type.code);
            map.put("name", type.value);
            list.add(map);
        }
        return list;
    }

    public static String getValueByCode(Integer code){
        if (code == null)
            return null;
        for (LinkEnum e : LinkEnum.values())
            if (e.getCode() == code)
                return e.getValue();

        return null;
    }
}
